<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>不同位置this的指代</title>
</head>
<body>
	
</body>
<script>
console.log('window下的this');
console.log(this);
function abcc(){
	console.log('abcc()下的this');
	console.log(this);
}
function deff() {
	console.log('deff()下的this');
	console.log(this);
	abcc();
}

var b  = {};
b.a = function() {
	console.log('b()下的this');
	console.log(this);
	var that = this;
	function test() {
		console.log('test()下的this');
		console.log(this);
		console.log(that);
	}
	test();
}
deff();
b.a();

var Story = function(){};
Story.prototype = {
	progress:'unknown',
	start:function() {
		this.progress = 'doing';
	}
}

var myStory = new Story();
myStory.start();
console.log('myStory.progress:');
console.log(myStory.progress);

var story = {
	progress:'unknown',
	start:function(){
		console.log('start()下的this');
		console.log(this);
		story.progress = 'start';
		//this是window对象
		// this.progress = 'start';
		console.log('this.progress后的story');
		console.log(story);
	}
};

var start = story.start;
start();
console.log('start:');
console.log(story);
console.log('story.progress:');
console.log(story.progress);

console.log('start.progress:');
console.log(start.progress);

// var a = {"x": 1};
// var b = a;
// a.x = 5;
// b.x; 
// console.log(b);
// a = {"x":3};
// b.x;
// console.log(b);
// a.x = 4;
// b.x;
	
// console.log(b);

// for(var i = 0; i < 10; i++) {
// 	var b = i;
//     (function(e) {
//     	setTimeout(function() {
//     	console.log('xunhuan');
//     	console.log(this);
//         console.log(e);  
//     }, 1000);
// 	})(i);
// }
</script>
</html>